<template>
    <div>
        <a-modal
            v-model:visible="visible"
            title="描述模板详情"
            @ok="handleOk"
            width="900px"
            wrapClassName="recitingDiscipline-full-modal"
            :footer="null"
            :dialogStyle="{top:'20px'}"
        >
            <a-spin tip="正在加载中..." :spinning="lastMeetingSpinning">
                <a-button style="margin-right:5px;" size="small" class="blue-btn" type="primary" @click="copyFormattedContent(currentData.fmbnr)" icon="copy">复制模板</a-button>
                <div :style="{height:(windowInnerHeight - 115 )+'px'}" style="overflow-y: auto;">
                    <div v-html="currentData.fmbnr"></div>
                </div>
                <div
                    ref="editableDivRef"
                    :contenteditable="true"
                    style="position: absolute; left: -9999px; top: -9999px;"
                ></div>
            </a-spin>
        </a-modal>
    </div>
</template>
<script>
import { openFileReadOnly, } from './service/index'
import YchConstant from "@/api/YchConstant";
export default {
    components:{

    },
    props:{

    },
    data(){
        return{
            iframeKey:null,
            programDataiframeSrc:'',
            windowInnerHeight:window.innerHeight,
            visible:false,
            currentData:{},
            lastMeetingSpinning:false,
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        getData(row){
            this.currentData = row
        },
        copyFormattedContent(val) {
            // 将 HTML 内容设置为可编辑区域的 innerHTML
            this.$refs.editableDivRef.innerHTML = val;
    
            // 选择可编辑区域的内容
            const range = document.createRange();
            range.selectNodeContents(this.$refs.editableDivRef);
            const selection = window.getSelection();
            selection.removeAllRanges();
            selection.addRange(range);

            //console.log('我复制什么',this.$refs.editableDivRef.innerHTML)
            try {
            // 尝试复制内容到剪贴板（这里只复制纯文本，因为直接复制 HTML 是不安全的）
            // 注意：这里只是复制了纯文本，如果你想要复制 HTML，需要目标编辑器支持
                document.execCommand('copy');
                // alert('已复制带格式内容到剪贴板！');
                this.$message.success('复制成功！')
            } catch (err) {
                // 处理复制失败的情况
                // console.error('复制失败：', err);
                this.$message.warning('复制失败！')
            }
    
            // 清除选择
            selection.removeAllRanges();
        },
        handleOk(){

        }
    }
}
</script>
<style lang="less">
.recitingDiscipline-full-modal{
    .ant-modal{
        padding: 0;
    }
    .ant-modal-body{
        padding: 8px
    }
}
</style>